home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 9
/
Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO
/
002a
/
be310.zip
/
FACT.CHS
< prev
next >
Wrap
Text File
|
1993-06-01
|
911b
|
29 lines
/* CHESS FUNCTION(S): FACT.CHS -- standalone Chess program
/* DATE:
/* AUTHOR:
/*
/* DESCRIPTION: this does a factorial generation -- useful as an
/* example of recursion
{
char temp[30];
int i;
temp[0]=0;
if((get_str(temp,"Find factorial of What number (1-12)?",2)%256)!=27){
/* if the user didn't press escape
i=atoi(temp); /* convert to an integer
i=do_fact(i); /* find its factorial
msg("%s factorial is %ld",temp,i); /* print it out
getkey(); /* wait for a keypress
}
}
do_fact /* this function is a recursive one
int n; /* single parameter
{
if((n<1)||(n>12)) /* if illegal, return 0
return(0);
else if(n==1) /* if we are done with recursive call
return(1);
else /* else, recurse another level
return(do_fact(n-1)*n);
}